package com.fanco.learn_datastruct_leetcode.juc;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author qiaowang 2021/8/19
 * 描述
 */
public class MyThreadPoolDemo {
    public static void main(String[] args) {

//        ExecutorService executorService = Executors.newFixedThreadPool(5);
//        ExecutorService executorService = Executors.newSingleThreadExecutor();
        ExecutorService executorService = Executors.newCachedThreadPool();

        try {
            for (int i = 0; i <10; i++) {
                int finalI = i;
                executorService.execute(() ->{
                    System.out.println("第"+ finalI +"个线程运行");
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            executorService.shutdown();
        }




    }
}
